package com.alibaba.csp.sentinel.dashboard.rule.nacos.degrade;

import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.AbstractRuleProvider;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.NacosConfigUtil;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import org.springframework.stereotype.Component;

/**
 * @author: baiml
 * @Title: DegradeRuleNacosProvider
 * @ProjectName: 中台技术平台
 * @Depart 中台研发部
 * @Description:
 * @date: 2021/8/16 16:32
 */
@Component
public class DegradeRuleNacosProvider extends AbstractRuleProvider<DegradeRule,DegradeRuleEntity> {
    @Override
    protected String getRulePostFix(String appName) {
        return appName + NacosConfigUtil.DEGRADE_DATA_ID_POSTFIX;
    }

    @Override
    protected Class<DegradeRule> getDestType() {
        return DegradeRule.class;
    }

    @Override
    protected DegradeRuleEntity toRule(String appName, String ip, Integer port, DegradeRule degradeRule) {
        return DegradeRuleEntity.fromDegradeRule(appName, ip, port, degradeRule);
    }
}
